package com.yinbw.oracle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mybatisplus.common.model.param.ParamBean;
import com.mybatisplus.common.page.PageInfo;
import com.mybatisplus.common.page.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.yinbw.oracle.entity.TZzz;
import com.yinbw.oracle.mapper.TZzzMapper;
import com.yinbw.oracle.service.TZzzService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Slf4j
@Service
public class TZzzServiceImpl extends ServiceImpl<TZzzMapper, TZzz> implements TZzzService {

    @Autowired
    private TZzzMapper T_ZZZMapper;

    @Override
    public List<TZzz> queryList() {
        QueryWrapper<TZzz> queryWrapper = new QueryWrapper<>();
        List<TZzz> selectList = T_ZZZMapper.selectList(queryWrapper);
        return selectList;
    }

    @Override
    @Transactional
    public Boolean changeById(TZzz T_ZZZ) {
        int i = T_ZZZMapper.updateById(T_ZZZ);
        int a = 1/0;
        return true;
    }

    @Override
    @Transactional
    public Boolean removeById(Long id) {
        int i = T_ZZZMapper.deleteById(id);
        int a = 1/0;
        return true;
    }

    @Override
    @Transactional
    public Boolean saveData(TZzz T_ZZZ) {
        int insert = T_ZZZMapper.insert(T_ZZZ);
        int a = 1/0;
        return true;
    }

    @Override
    public PageVo page(ParamBean<TZzz> paramBean){
        PageVo<TZzz> pageVo = new PageVo<>();
        PageInfo pageInfo = new PageInfo();
        Page<TZzz> page = new Page<>(paramBean.getPageNum(), paramBean.getPageSize());
        QueryWrapper<TZzz> queryWrapper = new QueryWrapper<>();
        TZzz data = paramBean.getData();
        queryWrapper.eq(data.getTId().signum()!=0,"T_ID",data.getTId())
                    .eq(data.getTName()!=null,"T_NAME",data.getTName())
                    .eq(data.getTSex()!=null,"T_SEX",data.getTSex())
                    .eq(data.getTSid().signum()!=0,"T_SID",data.getTSid());
        T_ZZZMapper.selectPage(page,queryWrapper);
        pageVo.setDatas(page.getRecords());
        pageInfo.setTotalPageNum(Integer.valueOf(page.getTotal()+""));
        pageVo.setPageInfo(pageInfo);
        return pageVo;
    }
}
